package com.mathdroid.model.items;

import com.mathdroid.model.Model;

/**
 * This is used to check if items can be equipped or not.
 */
public final class ItemConstraints {

	/**
	 * Check if the item is equippable.
	 * @param i Item.
	 * @return Item is equippable.
	 */
	public boolean isEquippable(final Item i) {
		boolean b = true;
		
		/* If the item is unique and has a unique violation, it is not 
		 * equippable.
		 */
		if (i.isUnique() && this.hasUniqueViolation(i)) {
			b = false;
		}
		
		return b;
	}

	/**
	 * Check if the item is already equipped.
	 * @param i Item.
	 * @return Item is already equipped
	 */
	private boolean hasUniqueViolation(final Item i) {
		boolean violation = false;

		for (Item k : Model.getProfile().getEquipedItems().values()) {
			if (i.getName() == k.getName()) {
				violation = true;
			}
		}

		return violation;
	}
}
